<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<div class="bt">添加物品</div>
		<el-form label-width="100px" class="form">
			<el-form-item label="分类名称">
				<el-select v-model="vwpflid" class="select-block">
					<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
				</el-select>
			</el-form-item> 
			<el-form-item label="物品名称">
				<el-input v-model="vmc" placeholder="请输入物品名称" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="出售单价" v-if='pand'>
				<el-input v-model="vjg" v-if='pand' placeholder="请输入价格" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="单位名称">
				<el-select v-model="vdw" class="select-block" placeholder="请选择单位">
					<el-option :label="v.mc" :value="v.mc" v-for="v in dwcomboxlist"></el-option>
				</el-select>
			</el-form-item>
			<div class="search-item">
			</div>
			<!--<el-form-item label="是否上架">
				<el-tooltip placement="top" class="sx">
					<el-switch v-model="vsfsj" active-color="#13ce66" inactive-color="#ff4949" inactive-text="否" active-text="是" active-value="Y" inactive-value="N"></el-switch>
				</el-tooltip>
			</el-form-item> -->
			<!--<el-form-item label="是否配件" v-if='pj'>
				<el-tooltip placement="top" class="sx">
					<el-switch v-model="vispj" active-color="#13ce66" inactive-color="#ff4949" inactive-text="否" active-text="是" active-value="Y" inactive-value="N"></el-switch>
				</el-tooltip>
			</el-form-item> -->
			<el-form-item label="库存预警值">
				<el-input v-model="vkcxx" placeholder="请输入物品名称" class="select-block"></el-input> 
			</el-form-item> 
			<el-form-item label="物品描述">
				<el-input v-model="vms" type="textarea" :rows="2" placeholder="请输入描述" class="select-block"></el-input>
			</el-form-item> 
			<el-button type="primary" class="submit" @click="submit">添加</el-button> 
			<el-button type="danger" class="submit" @click="cancel">退出</el-button> 
		</el-form>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
//		props: ['data'],
		data() {
			return {
				sz:'',
				pand:true,
				vwpflid: '',
				vmc: '',
				vms: '',
				vjg: '',
				vdw: '',
				vsfsj: 'Y',
				vispj: 'N',
				vwpurl: '',
				vkcxx: '100',
				comboxlist: [],
				dwcomboxlist: [],
				dialogTableVisible: true,
				flist: ''
			}
		},
		created() {
			console.log(this.params,'ssssssssssss')
//			console.log(this.data,'ffff')
			this.getcomboxlist();
			this.getdwcomboxlist();
			this.vwpflid = this.params.vselectwpfxid;
			this.ispj = this.params.vispj;
			this.sz = this.params.sz;
			if(this.sz=='34'){
				this.pand=false;
			}
//			if(this.params.vispj=true){
//				this.vispj='Y';
////				this.title='添加配件';
//              this.pj=true;
//			}
//			if(this.params.vispj=false){
////				this.vispj='Y';
//				this.title='添加物品';
//			}
		},
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
				if(!this.vmc) {
					this.$message.warning('请选择物品分类名称');
					this.$store.state.loading = false;
					return;
				} else if(!this.vmc) {
					this.$message.warning('请输入物品名称');
					this.$store.state.loading = false;
					return;
				} 
//				else if(!this.vjg) {
//					this.$message.warning('请输入价格');
//					this.$store.state.loading = false;
//					return;
//				}
				else if(!this.vdw) {
					this.$message.warning('请选择单位');
					this.$store.state.loading = false;
					return;
				} else if(!this.vsfsj) {
					this.$message.warning('请选择是否上架');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					// wpflid: this.vwpflid,
					wpflid: this.vwpflid,
					mc: this.vmc,
					ms: this.vms,
					jg: this.vjg,
					dw: this.vdw,
					kcxx:this.vkcxx,
					sfsj: this.vsfsj,
					ispj: 'N',
					wpurl: this.vwpurl,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});

				//执行
				// console.log(params3)
				this.axios.post(this.$store.state.api + 'wpfx/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {type: 'add',cancel: false});
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', {
					type: 'add',
					cancel: true
				})
			},
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					keywork: this.jcmc,
					pageindex: 1,
					pagesize: 1000
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfl/list', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					}) 
			},
			getdwcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				})
				//执行
				this.axios.post(this.$store.state.api + 'bq/hddw', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.dwcomboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					}) 
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 10px;
			text-align: center;
		}
		.bt {
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			background: #50BFFF;
			margin-bottom: 20px;
			color: white;
			text-align: left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.form {
			text-align: center;
			margin-top: 20px;
		}
		.input {
			display: inline-block;
		}
		.select-block {
			display: block;
			width: 85%;
		}
		.submit {
			width: 120px;
		}
		.flist {}
		.el-form-item {
    margin-bottom: 12px;
}
	}
</style>